package cn.tedu.loding.controller;

import cn.tedu.loding.service.IBrandCategoryService;
import cn.tedu.loding.service.ICategoryAttributeTemplateService;
import cn.tedu.loding.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 处理类别与属性模板关联相关请求的控制器
 *
 */
@Api(tags = "03. 类别与属性模板关联管理模块")
@Slf4j
@RestController
@RequestMapping("/category-attributeTemplate")
public class CategoryAttributeTemplateController {

    @Autowired
    private ICategoryAttributeTemplateService categoryAttributeTemplateService;

    public CategoryAttributeTemplateController() {
        log.info("创建控制器对象：CategoryAttributeTemplateController");
    }

    @ApiOperation("绑定类别与属性模板的关联")
    @ApiOperationSupport(order = 100)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId", value = "类别id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "attributeTemplateId", value = "属性模板id", required = true, dataType = "long")
    })
    @PostMapping("/bind")
    public JsonResult<Void> bind(Long categoryId, Long attributeTemplateId) {
        log.debug("开始处理【绑定类别与属性模板的关联】的请求，类别：{}，属性模板：{}", categoryId, attributeTemplateId);
        categoryAttributeTemplateService.bind(categoryId, attributeTemplateId);
        return JsonResult.ok();
    }

    @ApiOperation("解绑类别与属性模板的关联")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "类别与属性模板关联的数据id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/unbind")
    public JsonResult<Void> unbind(@PathVariable Long id) {
        log.debug("开始处理【解绑类别与属性模板的关联】的请求：id={}", id);
        categoryAttributeTemplateService.unbind(id);
        return JsonResult.ok();
    }

}
